import React from 'react';
import { DeviceEventEmitter, Image, Platform, PermissionsAndroid, StyleSheet, Text, View, WebView } from 'react-native';

import Constant from '../Constant/Constant'
import ScreenUtils from '../Utils/ScreenUtils'
import ColorUtils from '../Utils/ColorUtils'
import ToastUtils from '../Utils/ToastUtils'
import HttpUtils from '../Utils/HttpUtils'
import StorageUtils from '../Utils/StorageUtils'

export default class NavigatorMap extends React.Component
{
    constructor(props)
    {
        super(props);
        this.state = {};
    }

    componentDidMount()
    {
    }

    componentWillUnmount()
    {
    }

    async requestLocationPermission()
    {
        try
        {
            const granted = await PermissionsAndroid.request(
                PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
                {
                    //第一次请求拒绝后提示用户你为什么要这个权限
                    'title': '获取定位权限',
                    'message': '允许获取定位权限'
                }
            )
            if (granted === PermissionsAndroid.RESULTS.GRANTED)
            {
                // this.show("你已获取了地址查询权限")
            } else
            {
                this.show("获取地址查询失败")
                ToastUtils.toastShortBottom('获取定位权限失败，请重试')
            }
        }
        catch (err)
        {
            this.show(err.toString())
        }
    }

    render()
    {
        return (
            <View style={styles.container}>
                <WebView
                    style={styles.web}
                    source={{uri: Constant.mapServer +'?type=dingwei', method: 'GET', headers: {'Cache-Control': 'no-cache'}}}
                    ref="webView"
                    startInLoadingState={true}
                    domStorageEnabled={true}
                />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: ColorUtils.bgColor,
    },
    web: {
        flex: 1,
    },
});
